package com.ayf.payment.game.api.channel.alipay.util;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ayf.payment.game.api.channel.alipay.AlipayApiException;
import com.ayf.payment.game.api.channel.alipay.AlipayClient;
import com.ayf.payment.game.api.channel.alipay.CertAlipayRequest;
import com.ayf.payment.game.api.channel.alipay.DefaultAlipayClient;
import com.ayf.payment.game.api.channel.alipay.internal.util.AlipaySignature;
import com.ayf.payment.game.api.channel.alipay.request.AlipayDataDataserviceBillDownloadurlQueryRequest;
import com.ayf.payment.game.api.channel.alipay.request.AlipayFundAccountQueryRequest;
import com.ayf.payment.game.api.channel.alipay.request.AlipayFundTransCommonQueryRequest;
import com.ayf.payment.game.api.channel.alipay.request.AlipayFundTransUniTransferRequest;
import com.ayf.payment.game.api.channel.alipay.response.AlipayDataDataserviceBillDownloadurlQueryResponse;
import com.ayf.payment.game.api.channel.alipay.response.AlipayFundAccountQueryResponse;
import com.ayf.payment.game.api.channel.alipay.response.AlipayFundTransCommonQueryResponse;
import com.ayf.payment.game.api.channel.alipay.response.AlipayFundTransUniTransferResponse;
import com.ayf.payment.game.api.dto.MerchantAlipayConfigDTO;
import com.ayf.payment.game.api.utils.Base64;
import com.ayf.payment.game.api.utils.SnowFlakeUtils;
import com.ayf.payment.game.api.utils.URLCoderUtil;
import com.ayf.payment.game.api.utils.ZipUtils;
import com.swwx.charm.commons.lang.utils.LogPortal;
import org.apache.http.*;
import org.apache.http.client.HttpClient;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.HttpClientBuilder;
import org.bouncycastle.jce.provider.BouncyCastleProvider;

import java.io.*;
import java.nio.charset.Charset;
import java.security.Security;
import java.util.HashMap;
import java.util.Map;

public final class AlipayHttpUtil {

    public static final int cache = 10 * 1024;
    public static final String splash = "Users/syf/billfile/";
    public static final String root = "/";

    static {
        Security.addProvider(new BouncyCastleProvider());
    }

    public static void main(String[] args) {
//        createSinglePayOrderTest();
//        querySinglePayOrderTest();
        queryAccountBalanceTest();
//        queryStatementUrlTest();

//        checkSyncNotifySignTest();
    }

    /**
     * 异步通知内容验签
     */
    public static void checkSyncNotifySignTest() {
        // 支付宝原始请求报文
        String requestBody = "charset=UTF-8&biz_content=%7B%22pay_date%22%3A%222020-03-12+12%3A27%3A01%22%2C%22biz_scene%22%3A%22DIRECT_TRANSFER%22%2C%22action_type%22%3A%22FINISH%22%2C%22pay_fund_order" +
                "_id%22%3A%2220200312110070001506900043317564%22%2C%22origin_interface%22%3A%22alipay.fund.trans.uni.transfer%22%2C%22out_biz_no%22%3A%22DF20200312687637770046476288%22%2C%22trans_am" +
                "ount%22%3A%220.91%22%2C%22product_code%22%3A%22TRANS_ACCOUNT_NO_PWD%22%2C%22order_id%22%3A%2220200312110070000006900042815442%22%2C%22status%22%3A%22SUCCESS%22%7D&utc_timestamp=1583" +
                "987221610&sign=BpQaI4krbN11DqG1LNdjrMH81rykYWhp0s8goME8M4jGDV0D7GqiiggRlWyNt%2B1mp%2FaIh7mmTaP09sg3hXGAewTMrpWieHYWxqTrWBUchc4CiyDcZcgFrpXCbDA5OaFEztEQrVaiTI69GSU7GI3aFVakAVt%2FSw2r" +
                "PgH3g4s0VbJIKviBKwU2pQrtGtn6QmE1Iv%2BPVB%2FJRfjKVQe6GM%2BWVDMgdvjP2ZtW9hwjI2ccvptOZT86B7WLXvWLQI%2F6oVNQtPE%2BTxpkkGbIWSWmml8F8fW7d5EOcoXn4eiZvlsAjuJvwbxqerPNggzPaC1aGSLVSbP%2B7Y1Jv" +
                "y08PK5zPIj70w%3D%3D&app_id=2021001141603544&version=1.1&sign_type=RSA2&notify_id=2020031200222122701044911400122713&msg_method=alipay.fund.trans.order.changed";

        requestBody = "charset=UTF-8&biz_content=%7B%22pay_date%22%3A%222020-03-12+12%3A27%3A01%22%2C%22biz_scene%22%3A%22" +
                "DIRECT_TRANSFER%22%2C%22action_type%22%3A%22FINISH%22%2C%22pay_fund_order+_id%22%3A%2220200312110070001506900043317564%22%2C%22origin_interface%22%3A%22alipay.fund.trans.uni.transfe" +
                "r%22%2C%22out_biz_no%22%3A%22DF20200312687637770046476288%22%2C%22trans_am+ount%22%3A%220.91%22%2C%22product_code%22%3A%22TRANS_ACCOUNT_NO_PWD%22%2C%22order_id%22%3A%222020031211007" +
                "0000006900042815442%22%2C%22status%22%3A%22SUCCESS%22%7D&utc_timestamp=1583+987221610&sign=BpQaI4krbN11DqG1LNdjrMH81rykYWhp0s8goME8M4jGDV0D7GqiiggRlWyNt%2B1mp%2FaIh7mmTaP09sg3hXGAew" +
                "TMrpWieHYWxqTrWBUchc4CiyDcZcgFrpXCbDA5OaFEztEQrVaiTI69GSU7GI3aFVakAVt%2FSw2r+PgH3g4s0VbJIKviBKwU2pQrtGtn6QmE1Iv%2BPVB%2FJRfjKVQe6GM%2BWVDMgdvjP2ZtW9hwjI2ccvptOZT86B7WLXvWLQI%2F6oVNQ" +
                "tPE%2BTxpkkGbIWSWmml8F8fW7d5EOcoXn4eiZvlsAjuJvwbxqerPNggzPaC1aGSLVSbP%2B7Y1Jv+y08PK5zPIj70w%3D%3D&app_id=2021001141603544&version=1.1&sign_type=RSA2&notify_id=2020031200222122701044911400122713&msg_method=alipay.fund.trans.order.changed";

        Map<String, String> params = new HashMap<>();
        try {
            String originrequestBody = URLCoderUtil.decode(requestBody);
            String[] paramsArry = originrequestBody.split("&");
            for (String pItem : paramsArry) {
                int firstIndex = pItem.indexOf("=");
                params.put(pItem.substring(0, firstIndex), pItem.substring(firstIndex + 1));
            }
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        String alipayPublicCertStr_pro = "LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURyekNDQXBlZ0F3SUJBZ0lRSUNBRENjYUNLend6U3Q4U2RoQkpjekFOQmdrcWhraUc5dzBCQVFzRkFEQ0JnakVMTUFrR0ExVUUKQmhNQ1EwNHhGakFVQmdOVkJBb01EVUZ1ZENCR2FXNWhibU5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SWh2Y05BUUVMCkJRQURnZ0VCQUNZTTlLWlJCMit0OHJGWTZtSW42ZXExZkRVSHd5SVR1UFEzcUZIdGxrcE1PNnNGOWdCR2JrblVKMVllZXhWMzlVSEgKODFpRHpaSEFoOTdNSjZFK0hJdXhGNHpFZWZhdHpvWmlqempZbHZTS0NuaStnTTMxMlJUdmN2K2F0bkJ6bmc5U3pSUWE3QUpGOGxRLwpaT1d2SzdaNld6SkcwS1hWTjJmNy9FWGVpUGFTeDJOaUhWVGt0VkVoenVGY0lIZmQ1NGJrbVd3bmpRbFNibGRmOUtNanZ4cUdIL1FZCkdrK21aeWxPU1hBZW02ODQrMGFhdThoSkVjcVEzOXRmdHhEUjZGN01hZHJXSFM2WCs0VmJYd2ZJMnRHaU5yTTc3TnZwcHBYY0t5TGoKRVVwVjE5UmErRTlUVFZIWUxvRmg3RFRHQVNGZEh1Y1dZQ0t6VnU0czdTSmdHMjA9Ci0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K";
        try {
            boolean result = checkSyncNotifySign(params, alipayPublicCertStr_pro);
            System.out.println("异步通知验签结果:" + result);
        } catch (AlipayApiException e) {
            e.printStackTrace();
        }
    }

    /**
     * 支付宝单笔代付下单测试
     */
    public static void createSinglePayOrderTest() {
        JSONObject routeConfig = getRouteConfig();
        String traceId = SnowFlakeUtils.getTraceId();
        String merchantOrderNo = SnowFlakeUtils.getUniqueId();
        JSONObject jsonParam = new JSONObject();
        jsonParam.put("out_biz_no", merchantOrderNo);
        jsonParam.put("trans_amount", 0.5);
        jsonParam.put("order_title", "测试转账");
        jsonParam.put("remark", "测试转账001");// 业务备注
        jsonParam.put("product_code", "TRANS_ACCOUNT_NO_PWD");
        JSONObject payeeInfoJsonParam = new JSONObject();
        payeeInfoJsonParam.put("identity", "orlska1097@sandbox.com");// 支付宝登录号，支持邮箱和手机号格式
        payeeInfoJsonParam.put("name", "沙箱环境");// 参与方真实姓名
        payeeInfoJsonParam.put("identity_type", "ALIPAY_LOGON_ID");
        jsonParam.put("payee_info", payeeInfoJsonParam);
        try {
            AlipayFundTransUniTransferResponse response = createSinglePayOrder(traceId, jsonParam, routeConfig.toJSONString());
            if (response.isSuccess()) {
                System.out.println("调用成功");
            } else {
                System.out.println("调用失败："+JSONObject.toJSONString(response));
            }
        } catch (AlipayApiException e) {
            e.printStackTrace();
        }
    }

    /**
     * 支付宝单笔代付-单据查询测试
     */
    private static void querySinglePayOrderTest() {
        JSONObject routeConfig = getRouteConfig();
        String traceId = SnowFlakeUtils.getTraceId();
        String merchantOrderNo = "686716942266052608";
        try {
            AlipayFundTransCommonQueryResponse response = querySinglePayOrder(traceId, merchantOrderNo, routeConfig.toJSONString());
            if (response.isSuccess()) {
                System.out.println("调用成功");
            } else {
                System.out.println("调用失败");
            }
        } catch (AlipayApiException e) {
            e.printStackTrace();
        }
    }

    /**
     * 支付宝账户余额查询测试
     */
    private static void queryAccountBalanceTest() {
        JSONObject routeConfig = getRouteConfig();
        String traceId = SnowFlakeUtils.getTraceId();
        try {
            AlipayFundAccountQueryResponse response = queryAccountBalance(traceId, routeConfig.toJSONString());
            if (response.isSuccess()) {
                System.out.println("调用成功，返回报文:" + JSON.toJSONString(response));
            } else {
                System.out.println("调用失败");
            }
        } catch (AlipayApiException e) {
            e.printStackTrace();
        }
    }

    private static void queryStatementUrlTest() {
        JSONObject routeConfig = getRouteConfig();
        String traceId = SnowFlakeUtils.getTraceId();
        try {
            String bill_date = "2020-03-10";
            AlipayDataDataserviceBillDownloadurlQueryResponse response = queryStatementUrl(traceId, bill_date, routeConfig.toJSONString());
            if (response.isSuccess()) {
                LogPortal.info("调用成功 URL[{}] 返回报文:{}", response.getBillDownloadUrl(), JSONObject.toJSONString(response.getBody()));
                HttpGet httpGet = new HttpGet(response.getBillDownloadUrl());
                try {
                    RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(3 * 1000).
                            setConnectionRequestTimeout(3 * 1000).
                            setSocketTimeout(3 * 1000). //超时最大等待时间5分钟
                            build();
                    HttpClient httpClient = HttpClientBuilder.create().setDefaultRequestConfig(requestConfig).build();
                    HttpResponse httpResponse = httpClient.execute(httpGet);
                    try {
                        int responseCode = 0;
                        HttpEntity entity = httpResponse.getEntity();
                        if (entity != null) {
                            responseCode = httpResponse.getStatusLine().getStatusCode();
                            InputStream inputStream = entity.getContent();
                            String filePath = getFilePath(httpResponse);
                            File file = new File(filePath);
                            file.getParentFile().mkdirs();
                            FileOutputStream fileout = new FileOutputStream(file);
                            /**
                             * 根据实际运行效果 设置缓冲区大小
                             */
                            byte[] buffer = new byte[cache];
                            int ch = 0;
                            while ((ch = inputStream.read(buffer)) != -1) {
                                fileout.write(buffer, 0, ch);
                            }
                            inputStream.close();
                            fileout.flush();
                            fileout.close();

                            String unzipFilePath = root + splash;
                            ZipUtils.unzip(filePath, unzipFilePath, false, Charset.forName("GBK"));
                        }
                    } finally {
                        httpGet.releaseConnection();
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }
            } else {
                System.out.println("调用失败");
            }
        } catch (AlipayApiException e) {
            e.printStackTrace();
        }
    }


    /**
     * 获取response要下载的文件的默认路径
     *
     * @param response
     * @return
     */
    public static String getFilePath(HttpResponse response) {
        String filepath = root + splash;
        String filename = getFileName(response);
        if (filename != null) {
            filepath += filename;
        } else {
            filepath += getRandomFileName();
        }
        return filepath;
    }

    /**
     * 获取response header中Content-Disposition中的filename值
     *
     * @param response
     * @return
     */
    public static String getFileName(HttpResponse response) {
        Header contentHeader = response.getFirstHeader("Content-Disposition");
        String filename = null;
        if (contentHeader != null) {
            HeaderElement[] values = contentHeader.getElements();
            if (values.length == 1) {
                NameValuePair param = values[0].getParameterByName("filename");
                if (param != null) {
                    try {
                        filename = param.getValue();
                    } catch (Exception e) {
                        LogPortal.error("下载文件名称获取发生{}异常", e, e.getClass().getName());
                    }
                }
            }
        }
        return filename;
    }

    /**
     * 获取随机文件名
     *
     * @return
     */
    public static String getRandomFileName() {
        return SnowFlakeUtils.getUniqueId();
    }


    /**
     * 构造支付宝测试路由配置参数
     *
     * @return
     */
    private static JSONObject getRouteConfig() {
        JSONObject routeConfig = new JSONObject();

        String alipayPublicCertStr_test = "LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURxRENDQXBDZ0F3SUJBZ0lRSUNBRENkanY1bzc0bzBoK2ZsRGZ3akFOQmdrcWhraUc5dzBCQVFzRkFEQ0JrVEVMTUFrR0ExVUUKQmhNQ1EwNHhHekFaQmdOVkJBb01Fa0Z1ZENCR2FXNWhibU5wWVd3Z2RHVnpkREVsTUNNR0ExVUVDd3djUTJWeWRHbG1hV05oZEdsdgpiaUJCZFhSb2IzSnBkSGtnZEdWemRERStNRHdHQTFVRUF3dzFRVzUwSUVacGJtRnVZMmxoYkNCRFpYSjBhV1pwWTJGMGFXOXVJRUYxCmRHaHZjbWwwZVNCRGJHRnpjeUF5SUZJeElIUmxjM1F3SGhjTk1qQXdNekE1TVRFd01qUXhXaGNOTWpNd016QTRNVEV3TWpReFdqQjYKTVFzd0NRWURWUVFHRXdKRFRqRVZNQk1HQTFVRUNnd001cktaNTY2eDU0NnY1YUtETVE4d0RRWURWUVFMREFaQmJHbHdZWGt4UXpCQgpCZ05WQkFNTU91YVVyK1M3bU9XdW5Tamt1SzNsbTcwcDU3MlI1N3VjNW9xQTVweXY1cHlKNlptUTVZV3M1WSs0TFRJd09EZ3hNREl4Ck9EQXdNamN4T0RRd2dnRWlNQTBHQ1NxR1NJYjNEUUVCQVFVQUE0SUJEd0F3Z2dFS0FvSUJBUURXUWhWWitZbGtYZExFVUx4QWpKQW4KQmZFSUN4WlhtWmFwcmo5cGFLN0pmRU1PMVpjV0FvWHhwV1pjUlJ0TlJuYldSWFlsY0dac1NaNWg1dDhUaXlsUFozd0J0WDZRdE1UTAoyOGhibkY5Nk44Y3o0TzZ4Y1VhVWsyMjJCTTQreDJmT1RXOGZkQ051b1B6anh5QUhqTk42cXB6WEExRmRVVEoxSXJmTEYyY1A2UjlRClJYeVJ5UFdVZzFOSE9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kg1cVoAY6ej8Z/s7SZhzn5XPcWSCLIoe3FDtxC56u4HGdTc3N0fwO9FhTeThEgxpO9Z1SsWih2i4VYBsAZnypInqXsET80VSf/Tseh/2J4ZtSWow9b7s+FLBsbgFW/SNDg4b/zt/dH3Vxt5AQKBgGGURcognEOEpP2EB54UDUSmUcIggG4xWc9M6SR0uLvYsTrvwdSiwZeYstSGhP134xkqkdKjD5/iLS+zyQSHVusNq5XrH3+yH6X5CNMnDv7f3LbIqvL00+0OqMcH/ahp7V4n3IjBLqYxpSyIQbQqjpS0vb3k93ekITZHS31YH4tH";
        routeConfig.put("appId", "2016101700709988");
        routeConfig.put("serverUrl", "https://openapi.alipaydev.com/gateway.do");
        routeConfig.put("alipay_public_cert", alipayPublicCertStr_test);
        routeConfig.put("root_cert", rootCertStr_test);
        routeConfig.put("merchant_public_cert", certStr_test);
        routeConfig.put("merchant_private_key", privateKey_test);
        routeConfig.put("alipay_user_id", "2088102180027184");// UID

        // 生产
//        String certStr_pro="LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUVyakNDQTVhZ0F3SUJBZ0lRSUNBRENlMjR3TXkzL3hiRWhNR1BLVEFOQmdrcWhraUc5dzBCQVFzRkFEQ0JnakVMTUFrR0ExVUUKQmhNQ1EwNHhGakFVQmdOVkJBb01EVUZ1ZENCR2FXNWhibU5wWVd3eElEQWVCZ05WQkFzTUYwTmxjblJwWm1sallYUnBiMjRnUVhWMAphRzl5YVhSNU1Ua3dOd1lEVlFRREREQkJiblFnUm1sdVlXNWphV0ZzSUVObGNuUnBabWxqWVhScGIyNGdRWFYwYUc5eWFYUjVJRU5zCllYTnpJREVnVWpFd0hoY05NakF3TXpBNU1UQTBNalU0V2hjTk1qSXdNekE1TVRBME1qVTRXakIyTVFzd0NRWURWUVFHRXdKRFRqRXEKTUNnR0ExVUVDZ3doNWE2SjZLK0I1YTZkNUwraDVvR3Y1b3FBNXB5djVweUo2Wm1RNVlXczVZKzRNUTh3RFFZRF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ubsJQpojbwEm3PD9mjYVp7hNAJdCy4gkBzMO0bJFSy0pklQsQKBgGXNxU59BIfeQK9g21YwsZ9067HLwjD1fn3j9h3VpYvSgHOrME0MId+rUSrFT11bXjiRP/sC4PUP9TTpxvsusPZHY0wyFLFnr16sGc/2Bd07X7TtqIzCXo0nCP/oqHBTyEjMEr71+2JQxOoLM4YP3ABPawmvIIhjO8GQZOH5w5k5AoGAHm7rIxWnSleYlusO2zLXM1SqRzlt9L6vmTfXYXR94hMErhyM/cwJ/VYb0HSTUagt3kVgKTgn6HuvuGt+hpUiT/kMR7Yeic4uhdfbNYGmw8pjMYYtN7sJ6p9iOt9v7pls4w6GwJRJPtRzs1Bj2wrWpjeAVK0GrQDYV7/VrEz7NZw=";
//        routeConfig = new JSONObject();
//        routeConfig.put("appId","2021001141603544");
//        routeConfig.put("serverUrl","https://openapi.alipay.com/gateway.do");
//        routeConfig.put("alipay_public_cert",alipayPublicCertStr_pro);
//        routeConfig.put("root_cert",rootCertStr_pro);
//        routeConfig.put("merchant_public_cert",certStr_pro);
//        routeConfig.put("merchant_private_key",privateKey_pro);
//        routeConfig.put("alipay_user_id","2088431237207904");// UID
        return routeConfig;
    }

    /**
     * 支付宝单笔转账到支付宝账户
     *
     * @param traceId
     * @param jsonParam
     * @param routeConfig
     * @return
     * @throws AlipayApiException
     */
    public static AlipayFundTransUniTransferResponse createSinglePayOrder(String traceId, JSONObject jsonParam,
                                                                          String routeConfig) throws AlipayApiException {
        JSONObject payRouteJson = JSON.parseObject(routeConfig);
        CertAlipayRequest certAlipayRequest = new CertAlipayRequest();
        certAlipayRequest.setAppId(payRouteJson.getString("appId"));
        certAlipayRequest.setCharset("UTF-8");
        certAlipayRequest.setFormat("json");
        certAlipayRequest.setServerUrl(payRouteJson.getString("serverUrl"));
        certAlipayRequest.setSignType("RSA2");
        certAlipayRequest.setAlipayPublicCertPath(payRouteJson.getString("alipay_public_cert"));
        certAlipayRequest.setRootCertPath(payRouteJson.getString("root_cert"));
        certAlipayRequest.setCertPath(payRouteJson.getString("merchant_public_cert"));
        certAlipayRequest.setPrivateKey(payRouteJson.getString("merchant_private_key"));
        AlipayClient alipayClient = new DefaultAlipayClient(certAlipayRequest, true);
        jsonParam.put("biz_scene", "DIRECT_TRANSFER");
        AlipayFundTransUniTransferRequest request = new AlipayFundTransUniTransferRequest();
        request.setTraceId(traceId);
        request.setBizContent(jsonParam.toJSONString());
        return alipayClient.certificateExecute(request);
    }

    /**
     * 支付宝单笔转账到支付宝账户
     *
     * @param traceId
     * @param jsonParam
     * @param config
     * @return
     * @throws AlipayApiException
     */
    public static AlipayFundTransUniTransferResponse createSinglePayOrder2(String traceId, JSONObject jsonParam,
                                                                           MerchantAlipayConfigDTO config) throws AlipayApiException {

        CertAlipayRequest certAlipayRequest = new CertAlipayRequest();
        certAlipayRequest.setAppId(config.getAppId());
        certAlipayRequest.setCharset("UTF-8");
        certAlipayRequest.setFormat("json");
        certAlipayRequest.setServerUrl(config.getServerUrl());
        certAlipayRequest.setSignType("RSA2");
        certAlipayRequest.setAlipayPublicCertPath(config.getAlipayPublicCertBase64());
        certAlipayRequest.setRootCertPath(config.getRootCertBase64());
        certAlipayRequest.setCertPath(config.getPublicCertBase64());
        certAlipayRequest.setPrivateKey(config.getPrivateKey());
        AlipayClient alipayClient = new DefaultAlipayClient(certAlipayRequest, true);
        jsonParam.put("biz_scene", "DIRECT_TRANSFER");
        AlipayFundTransUniTransferRequest request = new AlipayFundTransUniTransferRequest();
        request.setTraceId(traceId);
        request.setBizContent(jsonParam.toJSONString());
        return alipayClient.certificateExecute(request);
    }

    /**
     * 支付宝账户余额查询
     *
     * @param traceId
     * @param config
     * @return
     * @throws AlipayApiException
     */
    public static AlipayFundAccountQueryResponse queryAccountBalance2(String traceId, MerchantAlipayConfigDTO config) throws AlipayApiException {
        CertAlipayRequest certAlipayRequest = new CertAlipayRequest();
        certAlipayRequest.setAppId(config.getAppId());
        certAlipayRequest.setCharset("UTF-8");
        certAlipayRequest.setFormat("json");
        certAlipayRequest.setServerUrl(config.getServerUrl());
        certAlipayRequest.setSignType("RSA2");
        certAlipayRequest.setAlipayPublicCertPath(config.getAlipayPublicCertBase64());
        certAlipayRequest.setRootCertPath(config.getRootCertBase64());
        certAlipayRequest.setCertPath(config.getPublicCertBase64());
        certAlipayRequest.setPrivateKey(config.getPrivateKey());
        AlipayClient alipayClient = new DefaultAlipayClient(certAlipayRequest, true);
        JSONObject jsonParam = new JSONObject();
        jsonParam.put("alipay_user_id", config.getAlipayUserId());
        jsonParam.put("account_type", "ACCTRANS_ACCOUNT"); // 查询余额账户
        jsonParam.put("biz_scene", "DIRECT_TRANSFER"); // 开户场景码，与开户产品码不可同时传递
        AlipayFundAccountQueryRequest request = new AlipayFundAccountQueryRequest();
        request.setTraceId(traceId);
        request.setBizContent(jsonParam.toJSONString());
        return alipayClient.certificateExecute(request);
    }

    /**
     * 支付宝转账单据订单查询
     *
     * @param traceId
     * @param merchantOrderNo
     * @param config
     * @return
     * @throws AlipayApiException
     */
    public static AlipayFundTransCommonQueryResponse querySinglePayOrder2(String traceId, String merchantOrderNo,
                                                                          MerchantAlipayConfigDTO config) throws AlipayApiException {
        CertAlipayRequest certAlipayRequest = new CertAlipayRequest();
        certAlipayRequest.setAppId(config.getAppId());
        certAlipayRequest.setCharset("UTF-8");
        certAlipayRequest.setFormat("json");
        certAlipayRequest.setServerUrl(config.getServerUrl());
        certAlipayRequest.setSignType("RSA2");
        certAlipayRequest.setAlipayPublicCertPath(config.getAlipayPublicCertBase64());
        certAlipayRequest.setRootCertPath(config.getRootCertBase64());
        certAlipayRequest.setCertPath(config.getPublicCertBase64());
        certAlipayRequest.setPrivateKey(config.getPrivateKey());
        AlipayClient alipayClient = new DefaultAlipayClient(certAlipayRequest, true);
        JSONObject jsonParam = new JSONObject();
        jsonParam.put("product_code", "TRANS_ACCOUNT_NO_PWD");
        jsonParam.put("biz_scene", "DIRECT_TRANSFER");
        jsonParam.put("out_biz_no", merchantOrderNo);
        AlipayFundTransCommonQueryRequest request = new AlipayFundTransCommonQueryRequest();
        request.setTraceId(traceId);
        request.setBizContent(jsonParam.toJSONString());
        return alipayClient.certificateExecute(request);
    }

    /**
     * 支付宝转账单据订单查询
     *
     * @param traceId
     * @param merchantOrderNo
     * @param routeConfig
     * @return
     * @throws AlipayApiException
     */
    public static AlipayFundTransCommonQueryResponse querySinglePayOrder(String traceId, String merchantOrderNo, String routeConfig) throws AlipayApiException {
        JSONObject payRouteJson = JSON.parseObject(routeConfig);
        CertAlipayRequest certAlipayRequest = new CertAlipayRequest();
        certAlipayRequest.setAppId(payRouteJson.getString("appId"));
        certAlipayRequest.setCharset("UTF-8");
        certAlipayRequest.setFormat("json");
        certAlipayRequest.setServerUrl(payRouteJson.getString("serverUrl"));
        certAlipayRequest.setSignType("RSA2");
        certAlipayRequest.setAlipayPublicCertPath(payRouteJson.getString("alipay_public_cert"));
        certAlipayRequest.setRootCertPath(payRouteJson.getString("root_cert"));
        certAlipayRequest.setCertPath(payRouteJson.getString("merchant_public_cert"));
        certAlipayRequest.setPrivateKey(payRouteJson.getString("merchant_private_key"));
        AlipayClient alipayClient = new DefaultAlipayClient(certAlipayRequest, true);
        JSONObject jsonParam = new JSONObject();
        jsonParam.put("product_code", "TRANS_ACCOUNT_NO_PWD");
        jsonParam.put("biz_scene", "DIRECT_TRANSFER");
        jsonParam.put("out_biz_no", merchantOrderNo);
        AlipayFundTransCommonQueryRequest request = new AlipayFundTransCommonQueryRequest();
        request.setTraceId(traceId);
        request.setBizContent(jsonParam.toJSONString());
        return alipayClient.certificateExecute(request);
    }


    /**
     * 支付宝账户余额查询
     *
     * @param traceId
     * @param routeConfig
     * @return
     * @throws AlipayApiException
     */
    public static AlipayFundAccountQueryResponse queryAccountBalance(String traceId, String routeConfig) throws AlipayApiException {
        JSONObject payRouteJson = JSON.parseObject(routeConfig);
        CertAlipayRequest certAlipayRequest = new CertAlipayRequest();
        certAlipayRequest.setAppId(payRouteJson.getString("appId"));
        certAlipayRequest.setCharset("UTF-8");
        certAlipayRequest.setFormat("json");
        certAlipayRequest.setServerUrl(payRouteJson.getString("serverUrl"));
        certAlipayRequest.setSignType("RSA2");
        certAlipayRequest.setAlipayPublicCertPath(payRouteJson.getString("alipay_public_cert"));
        certAlipayRequest.setRootCertPath(payRouteJson.getString("root_cert"));
        certAlipayRequest.setCertPath(payRouteJson.getString("merchant_public_cert"));
        certAlipayRequest.setPrivateKey(payRouteJson.getString("merchant_private_key"));
        AlipayClient alipayClient = new DefaultAlipayClient(certAlipayRequest, true);
        JSONObject jsonParam = new JSONObject();
        jsonParam.put("alipay_user_id", payRouteJson.getString("alipay_user_id"));
        jsonParam.put("account_type", "ACCTRANS_ACCOUNT"); // 查询余额账户
        jsonParam.put("biz_scene", "DIRECT_TRANSFER"); // 开户场景码，与开户产品码不可同时传递
        AlipayFundAccountQueryRequest request = new AlipayFundAccountQueryRequest();
        request.setTraceId(traceId);
        request.setBizContent(jsonParam.toJSONString());
        return alipayClient.certificateExecute(request);
    }

    /**
     * 支付宝对账单URL查询
     *
     * @param traceId
     * @param bill_date   日账单格式为yyyy-MM-dd
     * @param routeConfig
     * @return
     * @throws AlipayApiException
     */
    public static AlipayDataDataserviceBillDownloadurlQueryResponse queryStatementUrl(String traceId, String bill_date, String routeConfig) throws AlipayApiException {
        JSONObject payRouteJson = JSON.parseObject(routeConfig);
        CertAlipayRequest certAlipayRequest = new CertAlipayRequest();
        certAlipayRequest.setAppId(payRouteJson.getString("appId"));
        certAlipayRequest.setCharset("UTF-8");
        certAlipayRequest.setFormat("json");
        certAlipayRequest.setServerUrl(payRouteJson.getString("serverUrl"));
        certAlipayRequest.setSignType("RSA2");
        certAlipayRequest.setAlipayPublicCertPath(payRouteJson.getString("alipay_public_cert"));
        certAlipayRequest.setRootCertPath(payRouteJson.getString("root_cert"));
        certAlipayRequest.setCertPath(payRouteJson.getString("merchant_public_cert"));
        certAlipayRequest.setPrivateKey(payRouteJson.getString("merchant_private_key"));
        AlipayClient alipayClient = new DefaultAlipayClient(certAlipayRequest, true);
        JSONObject jsonParam = new JSONObject();
        jsonParam.put("bill_type", "signcustomer"); // 是指基于商户支付宝余额收入及支出等资金变动的帐务账单
        jsonParam.put("bill_date", bill_date); // 日账单格式为yyyy-MM-dd
        AlipayDataDataserviceBillDownloadurlQueryRequest request = new AlipayDataDataserviceBillDownloadurlQueryRequest();
        request.setTraceId(traceId);
        request.setBizContent(jsonParam.toJSONString());
        return alipayClient.certificateExecute(request);
    }

    /**
     * 支付宝官方单笔转账验签
     *
     * @param params
     * @param alipayPublicCertStr
     * @return
     * @throws AlipayApiException
     */
    public static boolean checkSyncNotifySign(Map<String, String> params, String alipayPublicCertStr) throws AlipayApiException {
        if (params == null) {
            throw new AlipayApiException("支付宝官方单笔转账异步通知验签失败，params is null");
        }
        return AlipaySignature.rsaCertByteCheckV1(params, alipayPublicCertStr, params.get("charset"), params.get("sign_type"));
    }

    /**
     * 证书转换为字符串
     */
    public static void certToStr() {
        try {
            String path = "/Users/syf/Desktop/SEED/支付宝生产密钥/";
            File filename = new File(path + "alipayRootCert.crt");
            FileInputStream inputFromFile = new FileInputStream(filename);
            byte[] byteData = new byte[inputFromFile.available()];
            inputFromFile.read(byteData);
            inputFromFile.close();
            String pfxData = Base64.encode(byteData);
            System.out.println(pfxData);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
